package com.jet.member.controller;

import com.jet.core.result.ResultJson;
import com.jet.member.domain.dto.MemberLevelDto;
import com.jet.member.domain.dto.MemberLevelItemDto;
import com.jet.member.domain.entity.MemberLevel;
import com.jet.member.service.IMemberLevelService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/member/level")
public class MemberLevelController {

    private final IMemberLevelService memberLevelService;

    public MemberLevelController(IMemberLevelService memberLevelService) {
        this.memberLevelService = memberLevelService;
    }

    @PostMapping
    public ResultJson<Void> create(@RequestHeader long merchantNo,
                                   @RequestHeader long storeNo,
                                   @RequestHeader String accountId,
                                   @Validated @RequestBody MemberLevelDto dto) {
        memberLevelService.batchEdit(merchantNo, dto);
        return ResultJson.ok();
    }

    @GetMapping
    public ResultJson<List<MemberLevel>> list(@RequestHeader long merchantNo,
                                              @RequestHeader long storeNo,
                                              @RequestHeader String accountId) {
        return ResultJson.ok(memberLevelService.findAllByMerchantNo(merchantNo));
    }
}
